﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <title>手动子流程</title>
    <link href="../../../Comm/Style/CommStyle.css" rel="stylesheet" type="text/css" />
    <link href="../../../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <link href="../../../Scripts/easyUI/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../../../Scripts/easyUI/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="../../../Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="../../../Scripts/easyUI/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../../../Scripts/QueryString.js" type="text/javascript"></script>
    <script type="text/javascript" src="../../../Scripts/config.js"></script>
    <script type="text/javascript" src="../../../Comm/Gener.js"></script>
    <script src="../../../Scripts/EasyUIUtility.js" type="text/javascript"></script>
    <base target="_self" />
    <script type="text/javascript">
        var keyWord = "";
        var nodeID = GetQueryString("FK_Node");
        var orgNo = GetQueryString("OrgNo");
        var webUser = new WebUser();
        //页面启动函数.
        $(function () {
            $("#Msg").html("<img src=../../../Img/loading.gif />&nbsp;正在加载,请稍后......");

            //求出来已经设置的延续子流程.
            GetData();

        });

        function SearchIt() {
            keyWord = promptGener('请输入关键字', keyWord);
            if (keyWord == null || keyWord == undefined)
                keyWord = "";
            GetData();
        }
        function GetData() {

            var orgNo = GetQueryString("OrgNo");
            if (orgNo == undefined || orgNo == "undefined")
                orgNo = "ccflow";


            var dt = new Entities("BP.WF.Flows");
            if (webUser.CCBPMRunModel == 0)
                dt.RetrieveCond("Name", "like", '%' + keyWord + '%', "No");
            else
                dt.RetrieveCond("Name", "like", '%' + keyWord + '%', "OrgNo", "=", orgNo, "No");

            var Hands = new Entities("BP.WF.Template.SFlow.SubFlowHands");
            Hands.Retrieve("FK_Node", nodeID, "SubFlowType", 0);


            var html = "";
            for (var i = 0; i < dt.length; i++) {

                var en = dt[i];

                html += "<tr>";
                var orgNo = en.OrgNo || "";
                html += "<td>" + orgNo + "</td>";
                //  html += "<td>" + en.FK_FlowSortText + "</td>";
                html += "<td>" + en.No + "</td>";
                html += "<td>" + en.Name + "</td>";

                var isHave = false;
                for (var myidx = 0; myidx < Hands.length; myidx++) {

                    var Hand = Hands[myidx];
                    if (Hand.FK_Flow == en.No) {
                        isHave = true;

                        if (Hand.FlowName != en.Name) {

                            var HandEn = new Entity("BP.WF.Template.SFlow.SubFlowHand", Hand);
                            HandEn.FlowName = en.Name;
                            HandEn.Update();
                            //Hand.Update();
                        }
                        break;
                    }
                }

                if (isHave == false)
                    html += "<td><a href=\"javascript:CheckIt('" + en.No + "','" + en.Name + "');\" >选择</a></td>";
                else
                    html += "<td><font color=red>已存在</font></td>";

                html += "</tr>";
            }

            $("#SubFlows").html(html);
        }
        function CheckIt(flowNo, name) {

            if (window.confirm('您确定要增加吗？') == false)
                return;

            var nodeID = GetQueryString("FK_Node");

            var ens = new Entities("BP.WF.Template.SFlow.SubFlowHands");
            ens.Retrieve("FK_Node", nodeID, "SubFlowNo", flowNo, "SubFlowType", 0);

            if (ens.length == 1) {
                alert("该流程已经存在");
                return;
            }

            var myNode = new Entity("BP.WF.Node", nodeID);

            var en = new Entity("BP.WF.Template.SFlow.SubFlowHand");

            en.SubFlowNo = flowNo;
            en.FK_Node = nodeID;
            en.SubFlowType = 0;
            en.SubFlowName = name;
            en.FK_Flow = myNode.FK_Flow;

            var myen = en.Insert();

            SetHref('../../../Comm/RefFunc/EnOnly.htm?EnName=BP.WF.Template.SFlow.SubFlowHand&PKVal=' + myen.MyPK);

            //alert('当前流程已经加入了延续流程中.');
        }

    </script>
</head>
<body>
    <table id="Table1" style="width: 100%">
        <caption>
            请选择一个子流程
        </caption>
        <thead>
            <tr>
                <th>
                    组织编号
                </th>
                <th>
                    流程编号
                </th>
                <th>
                    名称<div style='float:right'><img src='../../../Img/Search.png' style='width:24px;' onclick='SearchIt();'></div>
                </th>
                <th>
                    操作
                </th>
            </tr>
        </thead>
        <tbody id="SubFlows">
        </tbody>
    </table>
</body>
</html>
